home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
ca29_3.zip
/
REMAP.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1992-03-23
|
28KB
|
1,165 lines
S29 = "INTERNAL" ; Set your editor here
; ; .. "INTERNAL" -> Our own editor
; ----- COM-AND Compile remap table
;
; This script opens a window asking 1) to compile new remap, 2) turn
; remapping on, and 3) turn remap off.
;
; The big job, of course, if the compilation of remapping values.
; The result of the compilation is saved unconditionally as COM-AND.RMP.
;
; R.McG, commenced 2/89
; updated 3/92 (to use internal editor)
; ----- Usages -----------------
; S29 -----> The fully qualified EDITOR program file name
; S19 -----> COM-AND.RMP file name to be used
; S18 -----> Source file being compiled
; N99 -----> The # of errors in compilation
; N98 -----> The output file size
; N97 -----> # name commands to allow (set in SELECT)
; FLAG(9) -> Escape during compile (wait for another ESC)
; FLAG(8) -> If true, syntax check only
; ------------------------------
; Initialization
;
;* TRACE ON
ON ESCAPE GOSUB Exit ; SAVE is performed in Window
LEGEND " Remap compiler (ver 1.2)"
SET TTHRU OFF ; Disallow typeahead
GOSUB Set_Fname ; Get current fname
UPPER S19 ; Make nice for display
;
; Open a window
;
GOSUB Window ; Open main window
;
; Wait for a keystroke
;
Keyin:
LOCATE 18,20
ATSAY 18,20 (default) " "
KEYGET S0
IF NULL S0(1:3)
ATSAY 18,20 (default) S0
ENDIF
;
; Interpret the response
;
SWITCH S0
CASE "1" ; Compile
GOSUB Compile
ENDCASE
CASE "2" ; Syntax
GOSUB Syntax
ENDCASE
CASE "3" ; Search for file
GOSUB Alt_F
ENDCASE
CASE "4" ; Edit a file
GOSUB Edit
ENDCASE
CASE "5" ; Remap on
GOSUB Mapon
ENDCASE
CASE "6" ; Remap off
GOSUB Mapoff
ENDCASE
DEFAULT ; None of the above
SOUND 100,100
GOTO Keyin ; Try again
ENDCASE
ENDSWITCH
GOTO KEYIN
;
; ----- Subroutine Exit - terminate the process
;
Exit:
DO ; CLose any open windows
WCLOSE
UNTIL FAILURE
EXIT
;
; ----- Subroutine Mapon - turn on mapping (using current file)
;
MapOn:
SET REMAP ON ; Enable
RETURN
;
; ----- Subroutine MapOff - turn off mapping
;
MapOff:
SET REMAP OFF ; Disable
RETURN
;
; ----- Perform an Alt-F - file search
;
Alt_F:
WOPEN 10,1 13,78 (default) ErrEsc
ATSAY 10,3 (default) " Search for files "
ATSAY 11,3 (default) "Enter a search template (e.g. 'd:\subd\x*.AR?')."
ATSAY 12,3 (default) "-> "
ATSAY 13,30 (default) " Press ESC to cancel "
ATGET 12,6 (default) 50 S0
WCLOSE
;
; If not null, perform the request
;
IF NOT NULL S0
DIR S0 ; Make upper case
ENDIF
RETURN
;
; ----- Invoke an editor to edit a file
;
Edit:
IF NOT NULL S29 GOTO Edit100
;
; Open a window and ask for the editor's name
;
WOPEN 10,1 13,78 (default) ErrEsc
ATSAY 10,3 (default) " Edit file "
ATSAY 11,3 (default) "Enter the editor's name, fully qualified (e.g. C:\PE.EXE)."
ATSAY 12,3 (default) "-> "
ATSAY 13,30 (default) " Press ESC to cancel "
ATGET 12,6 (default) 50 S0 ; ErrEsc clears S0, so we use it
WCLOSE
IF NULL S0 RETURN ; Return on empty answer
S29 = S0 ; Save for next time
;
; Open another window and ask for the file name
;
Edit100:
WOPEN 10,1 13,78 (default) ErrEsc
ATSAY 10,3 (default) " Edit file "
ATSAY 11,3 (default) "Enter the file name to be edited:"
ATSAY 12,3 (default) "-> "
ATSAY 13,30 (default) " Press ESC to cancel "
ATGET 12,6 (default) 50 S0 ; ErrEsc clears S0, so we use it
WCLOSE
;
; If not null, perform the request
;
IF NOT NULL S0 and (NOT NULL S29 and NOT FIND S29 "INTERNAL")
RUN S29 * " " *S0 ; Make upper case
IF FAILED S29 = "INTERNAL" ; Clear S29 if failed
ENDIF
IF (NULL S29 or FIND S29 "INTERNAL") and NOT NULL S0 EDIT S0
RETURN
;
; ----- Construct the file name we'll use for COM-AND.RMP
;
Set_Fname:
S19 = "COM-AND.RMP" ; Default to current subdir
IF ISFILE S19 ; Look for file on default subdir
RETURN ; Exit here
ENDIF
;
; ----- Construct the file with the COM-AND= pathing (if provided)
;
ENVIRON S1 "COM-AND=" ; Look for COM-AND= environment var
IF FOUND ; If environment variable found
LENGTH S1 N0 ; Get its length
N0 = N0-1 ; Point to last char in string
IF not STRCMP S1(n0:n0) "\"
N0 = N0+1
CONCAT S1(n0) "\"
ENDIF
ENDIF
S19 = S1&"COM-AND.RMP" ; Concatenate path and name
RETURN
;
; ----- Subroutine: error
; .. Open a window, display, and and await keypress
; S0,S1 pass the message(s) to display
;
Error:
WOPEN 10,1, 13,77 (contrast) ErrEsc
ATSAY 11, 3 (contrast) S0(0:73)
ATSAY 12, 3 (contrast) S1(0:73)
ATSAY 13,26 (contrast) " Press any key to continue "
SOUND 880,100
KEYGET S0 ; Wait for any key
WCLOSE ; Restore screen under
RETURN ; And return to caller
;
; Escape during "Error" window
;
ErrEsc:
S0 = "" ; Make S0 null
RETURN ; And return to KEYGET above
;
; ----- Subroutine: Test S0 for a valid (known) keycode
; Parameter S0 ------> The keycode being passed
; Return: FLAG(0) <- TRUE if erroneous keycode
; S0 <------ The converted keycode (if FLAG(0) false)
; N0 <------ The length of the converted keycode
;
Keycode:
LJ S0 ; Force left justification
S0 = S0&"" ; Trim trailing blanks
SET FLAG(0) OFF ; Default return value
LENGTH S0 N0 ; Compute len of parm
;
; Catch decimal and hex numbers here
;
IF NUMERIC S0(0:0) ; Case insensitive test here
ATOI S0 N0 ; Convert value
IF (NOT ERROR) and (GE N0 0 and LE N0 255)
ITOC N0 S0 ; Return value 0-255 as char
N0 = 1 ; Set rtn length
RETURN
ENDIF
ENDIF
;
; Switch according to length here
;
SWITCH N0
CASE 1 ; 1 char wide
GOTO TEKE100
ENDCASE
CASE 2 ; 2 chars wide
GOTO TEKE200
ENDCASE
CASE 3 ; 3 chars wide
GOTO TEKE300
ENDCASE
CASE 4 ; 4 chars wide
GOTO TEKE400
ENDCASE
CASE 5 ; 5 chars wide
GOTO TEKE500
ENDCASE
CASE 6 ; 6 chars wide
GOTO TEKE600
ENDCASE
DEFAULT
SET FLAG(0) ON ; Others are errors
RETURN
ENDCASE
ENDSWITCH
;
; ***** Single character keycode here (take char as-is)
;
TEKE100:
N0 = 1 ; Return length here (char already in S0)
RETURN
;
; ***** Two character keycode here: First: ^chars
;
TEKE200:
IF STRCMP S0(0:0) "^" ; Caret initially
UPPER S0 ; Make upper case
CTOI S0(1:1) N0
ITOC (N0-64) S0 ; Convert to control form, and place
N0 = 1
RETURN
ENDIF
;
; Catch F0-F9
;
IF FIND "F1,F2,F3,F4,F5,F6,F7,F8,F9" S0 N0
IF NE 0 (N0\3) ; Modulo divide (remainder)
SET FLAG(0) ON ; .. catch e.g. "0,"
RETURN
ENDIF
ITOC 0 S0
ITOC (0x3b+N0/3) S0(1)
N0 = 2
RETURN
ENDIF
;
; Catch cr and bs here
;
SWITCH S0
CASE "CR" ; Carriage Rtn
ITOC 13 S0
N0 = 1
RETURN
ENDCASE
CASE "BS" ; Carriage Rtn
ITOC 8 S0
N0 = 1
RETURN
ENDCASE
ENDSWITCH
;
; Other pairs are errors
;
SET FLAG(0) ON ; Others are errors
RETURN
;
; ***** Three character keycode here: First, rtn a quoted character
;
TEKE300:
IF STRCMP S0(0:0) "`"" and STRCMP S0(2:2) "`""
S0 = S0(1:1)
N0 = 1 ; Return length here (char in S0)
RETURN
ENDIF
;
; Catch SF0-SF9, CF0-CF9, AF0-AF9, ^F0-^F9
;
UPPER S0
IF FIND "F1,F2,F3,F4,F5,F6,F7,F8,F9" S0(1:2) N0
IF NE (N0\3) 0 ; Modulo divide (remainder)
SET FLAG(0) ON ; .. catch e.g. "0,"
RETURN
ENDIF
;
; Look at the leading character
;
FIND "SCA^" S0(0:0) N1
SWITCH N1
CASE 0 ; AF0,AF1...
ITOC (0x54+N0/3) S0(1)
ENDCASE
CASE 1 ; CF0,CF1...